/*
Copyright (C) 2010 
Author		  Oliver Schenk
Contact		  Oliver.Schenk76@gmail.com

This program is free software; you can redistribute
it and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 3 of the License,
or (at your option) any later version.
This program is distributed in the hope that it will be useful, 
but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; 
if not, see <http://www.gnu.org/licenses/>.
*/

package SelfBookingSystem;
import java.io.IOException;
import javax.jdo.PersistenceManager;
import javax.jdo.Query;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class DeleteApp extends HttpServlet {

	private static final long serialVersionUID = 1L;
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
	throws IOException {

		//Variablen Deklaration
		String AppID = new String();

		String tmp = "";
		if (req.getParameter("AppID").compareTo(tmp) > 0){
			AppID = req.getParameter("AppID");
		}else{
			resp.sendRedirect("/Admin/index.jsp");
		}

		PersistenceManager pm = PMF.get().getPersistenceManager();
		try {
			
			System.out.println("AppID: " + AppID);
			AdminValues values = pm.getObjectById(AdminValues.class, AppID);
			pm.deletePersistent(values);
			
			Query query = pm.newQuery(UserToAppID.class);
			query.setFilter("AppID == AppIDParam");
		    query.declareParameters("String AppIDParam");
		    query.deletePersistentAll(AppID);		
		    	
		} finally {
				pm.close();
			}
				resp.sendRedirect("/Admin/index.jsp");
		
	}
}
